import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class LoadFile {
	/**
	 * @modulename LoadFile
	 * @description This class keeps track of all the information needed to construct a Load File for the TRESSEL machine.
	 * @callsequence none
	 * @inparam none
	 * @outparam none
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing Load File
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	// header record
	private static String moduleName;
	private static Integer executionStartAddress;
	private static Integer moduleLength;
	private static Integer loadAddress;
	private static Integer initialLoadAddress;
	private static String tressel;
	private static String version;
	private static String revision;
	
	// linker text record arrays
	private static List<Integer> loadAddressArray;
	private static List<String> codeArray;
	private static List<String> moduleNameArray;
	
	// end record
	private static Integer textRecordTotal = 0;
	
	private LoadFile() {}
	
	/**
	 * @modulename initialize
	 * @description initializes the values of the load file.
	 * @callsequence LoadFile.resetLoadFile;
	 * @inparam none
	 * @outparam none
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Travis Casper
	 * @createdate 11/24/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Travis	11/24	Created to Initialize the Values.	 
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static void initilize() {
		// header record
		moduleName = new String ("default");
		executionStartAddress = 0;
		moduleLength = 0;
		loadAddress = 0;
		initialLoadAddress = 0;
		tressel = "TRESSEL";
		version = "1.0";
		revision = "1.0";
		
		// linker text record arrays
		loadAddressArray = new ArrayList<Integer>(0);
		codeArray = new ArrayList<String>(0);
		moduleNameArray = new ArrayList<String>(0);
		
		// end record
		textRecordTotal = 0;
	}
	/**
	 * @modulename startLoadFile
	 * @description This module initializes the header record of the load file.
	 * @callsequence LoadFile.startLoadFile(String modName, Integer moduleStartAddress);
	 * @inparam (String) modName: this is the name of the first module, (Integer) moduleStartAddress: this is the start address of the first module
	 * @outparam none
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing Load File
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static void startLoadFile(String modName, Integer moduleStartAddress, 
			Integer moduleLength, Integer loadAddress) {
		LoadFile.moduleName = modName;
		LoadFile.executionStartAddress = moduleStartAddress;
		LoadFile.moduleLength = moduleLength;
		LoadFile.initialLoadAddress = loadAddress;
	}
	/**
	 * @modulename returnModuleName
	 * @description This module returns the module name of the first module
	 * @callsequence LoadFile.returnModuleName();
	 * @inparam none
	 * @outparam (String) the module name of the first module
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing Load File
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnModuleName(){
		return LoadFile.moduleName;
	}
	/**
	 * @modulename returnStartAddress
	 * @description This module returns the start address of the first module
	 * @callsequence LoadFile.returnStartAddress();
	 * @inparam none
	 * @outparam (Integer) the start address of the first module
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing modules in Load File that are needed for the Simulator
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static Integer returnStartAddress(){
		return LoadFile.executionStartAddress;
	}
	/**
	 * @modulename returnModuleLength
	 * @description This module returns the length of the whole module
	 * @callsequence LoadFile.returnModuleLength();
	 * @inparam none
	 * @outparam (Integer) the length of the whole module
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing modules in Load File that are needed for the Simulator
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static Integer returnModuleLength(){
		return LoadFile.moduleLength;
	}	
	/**
	 * @modulename returnNumberOfTextRecords
	 * @description This module returns the number of text records in the load file
	 * @callsequence LoadFile.returnNumberOfTextRecords();
	 * @inparam none
	 * @outparam (Integer) the number of text records in the load file
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing modules in Load File that are needed for the Simulator
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static Integer returnNumberOfTextRecords(){
		return LoadFile.textRecordTotal;
	}
	/**
	 * @modulename returnInitialLoadAddress
	 * @description This module returns the initial Program Load Address in HEX
	 * @callsequence LoadFile.returnInitialLoadAddress();
	 * @inparam none
	 * @outparam (HEX) the initial program load address
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Travis Casper
	 * @createdate 11/22/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Travis, 11/22/09, added this functionality
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static Integer returnInitialLoadAddress(){
		return LoadFile.initialLoadAddress;
	}
	/**
	 * @modulename editLoadAddress
	 * @description This module edits the load address field of the load file header record
	 * @callsequence LoadFile.editLoadAddress(Integer moduleLoadAddress);
	 * @inparam (Integer) moduleStartAddress: this is the load address of the first module
	 * @outparam none
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing modules in Load File that are needed for the Simulator
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static void editLoadAddress(Integer moduleLoadAddress) {
		LoadFile.loadAddress = moduleLoadAddress;
	}
	/**
	 * @modulename returnLoadAddress
	 * @description This module returns the load address of the first module
	 * @callsequence LoadFile.returnLoadAddress();
	 * @inparam none
	 * @outparam (Integer) the load address of the first module
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing modules in Load File that are needed for the Simulator
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static Integer returnLoadAddress(){
		return LoadFile.loadAddress;
	}
	/**
	 * @modulename addTextRecord
	 * @description This module adds a text record to the load file
	 * @callsequence LoadFile.addTextRecord(Integer instructionAddress, String instructionCode, String instructionModule);
	 * @inparam (Integer) instructionAddress: the address of the isntruction, (String) instructionCode: the HEX encoding of the instruction, (String) instructionModule: the name of the module where this instruction came from
	 * @outparam none
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing modules in Load File that are needed for the Simulator
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static void addTextRecord(Integer instructionAddress, String instructionCode, String instructionModule){
		LoadFile.loadAddressArray.add(instructionAddress);
		LoadFile.codeArray.add(instructionCode);
		LoadFile.moduleNameArray.add(instructionModule);
		LoadFile.textRecordTotal++;
	}
	/**
	 * @modulename returnInstructionCode
	 * @description This module returns the hex encoding for the instruction at the given address
	 * @callsequence LoadFile.returnInstructionCode(Integer instructionAddress);
	 * @inparam (Integer) instructionAddress: the address of the instruction that you want
	 * @outparam (String) this is the hex encoding for the instruction at instructionAddress
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing modules in Load File that are needed for the Simulator
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnInstructionCode(Integer instructionAddress){
		return LoadFile.codeArray.get(loadAddressArray.indexOf(instructionAddress));
	}
	/**
	 * @modulename returnInstructionModuleName
	 * @description This module returns module name for the instruction at the given address
	 * @callsequence LoadFile.returnInstructionModuleName(Integer instructionAddress);
	 * @inparam (Integer) instructionAddress: the address of the instruction whose module name you want
	 * @outparam (String) this is the name of the module for the instruction at instructionAddress
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing modules in Load File that are needed for the Simulator
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnInstructionModuleName(Integer instructionAddress){
		return LoadFile.moduleNameArray.get(loadAddressArray.indexOf(instructionAddress));
	}
	/**
	 * @modulename returnInstructionLoadAddress
	 * @description returns the load address in the text record
	 * @callsequence LoadFile.returnInstructionLoadAddress();
	 * @inparam none
	 * @outparam (Integer) the location in the address array of the locationaddress
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Jamie Trefzger
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Jamie, 11/22/09, needed for outputting the load address in the formatfile.
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static Object returnInstructionLoadAddress(Integer instructionAddress){
		return LoadFile.loadAddressArray.get(instructionAddress);
	}
	/**
	 * @modulename returnDate
	 * @description returns the date for the load file
	 * @callsequence LoadFile.returnDate();
	 * @inparam none
	 * @outparam (String) the date of load file creation
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing modules in Load File that are needed for the Simulator
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnDate() {
		DateFormat dateFormat = new SimpleDateFormat("yyyy:ddd");
		Date date = new Date();
		return dateFormat.format(date);
	}
	/**
	 * @modulename returnTime
	 * @description returns the time for the load file
	 * @callsequence LoadFile.returnTime();
	 * @inparam none
	 * @outparam (String) the time of load file creation
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing modules in Load File that are needed for the Simulator
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnTime() {
		DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
		Date date = new Date();
		return dateFormat.format(date);
	}
	/**
	 * @modulename returnTressel
	 * @description returns the tressel field of the load file
	 * @callsequence LoadFile.returnTressel();
	 * @inparam none
	 * @outparam (String) the tressel field of the load file
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing modules in Load File that are needed for the Simulator
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnTressel() {
		return LoadFile.tressel;
	}
	/**
	 * @modulename returnVersion
	 * @description returns the version field of the load file
	 * @callsequence LoadFile.returnVersion();
	 * @inparam none
	 * @outparam (String) the version field of the load file
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing modules in Load File that are needed for the Simulator
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnVersion() {
		return LoadFile.version;
	}
	/**
	 * @modulename returnRevision
	 * @description returns the revision field of the load file
	 * @callsequence LoadFile.returnRevision();
	 * @inparam none
	 * @outparam (String) the revision field of the load file
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Nick Lister
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Nick, 11/20/09, began implementing modules in Load File that are needed for the Simulator
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static String returnRevision() {
		return LoadFile.revision;
	}
	/**
	 * @modulename resetLoadFile
	 * @description resets the values of the load file.
	 * @callsequence LoadFile.resetLoadFile;
	 * @inparam none
	 * @outparam none
	 * @errorstested See JUnit test cases
	 * @errorsgenerated See errata report
	 * @author Jamie Trefzger
	 * @createdate 11/20/09
	 * @modlog <p>
	 *         <ul>
	 *         Who/When/Why
	 *         <li>Jamie, 11/22/09, needed for the Junit test case
	 *         </ul>
	 *         Coding Standards Met: "Signed Code Leader(Jaron)"
	 *         <p>
	 *         Testing Standards Met: "Signed Test Leader(Jamie)"
	 */
	public static void resetLoadFile(){
		 moduleName = new String ("default");
			executionStartAddress = 0;
			moduleLength = 0;
			loadAddress = 0;
			initialLoadAddress = 0;
			tressel = "TRESSEL";
			version = "1.0";
			revision = "1.0";
			
			// linker text record arrays
			loadAddressArray = new ArrayList<Integer>(0);
			codeArray = new ArrayList<String>(0);
			moduleNameArray = new ArrayList<String>(0);
			
			// end record
			textRecordTotal = 0;
		}
}
